package com.cn.common;

public class MessageQueue implements Comparable<MessageQueue> {

    /**
     * 消息主题
     */
    private String topic;

    /**
     * 节点名称
     */
    private String brokerName;

    /**
     * 消息队列
     */
    private int queueId;

    public String getTopic() {
        return topic;
    }

    public MessageQueue setTopic(String topic) {
        this.topic = topic;
        return this;
    }

    public String getBrokerName() {
        return brokerName;
    }

    public MessageQueue setBrokerName(String brokerName) {
        this.brokerName = brokerName;
        return this;
    }

    public int getQueueId() {
        return queueId;
    }

    public MessageQueue setQueueId(int queueId) {
        this.queueId = queueId;
        return this;
    }

    @Override
    public int hashCode() {
        int prime = 31;
        int result = 1;
        result = prime * result + (brokerName == null ? 0 : brokerName.hashCode());
        result = prime * result + queueId;
        result = prime * result + (topic == null ? 0 : topic.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        MessageQueue other = (MessageQueue) obj;
        if (brokerName == null) {
            if (other.getBrokerName() != null) return false;
        } else if (!this.brokerName.equals(other.getBrokerName())) {
            return false;
        }
        if (queueId != other.getQueueId()) return false;
        if (topic == null) {
            if (other.getTopic() != null) return false;
        } else {
            if (!topic.equals(other.getTopic())) return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "MessageQueue{" +
                "topic='" + topic + '\'' +
                ", brokerName='" + brokerName + '\'' +
                ", queueId=" + queueId +
                '}';
    }

    @Override
    public int compareTo(MessageQueue o) {
        {
            int result = this.topic.compareTo(o.getTopic());
            if (result != 0) {
                return result;
            }
        }

        {
            int result = this.brokerName.compareTo(o.getBrokerName());
            if (result != 0) {
                return result;
            }
        }
        return this.queueId - o.getQueueId();
    }

    public static void main(String[] args) {
        MessageQueue messageQueue = new MessageQueue();
        messageQueue.setBrokerName("demo1");
        messageQueue.setQueueId(0);
        messageQueue.setTopic("demo");
    }
}
